/**
 * Created by Administrator on 2016/9/21.
 */
window.onload = function() {
    jQuery.noConflict();


    function removeCookie(name, path) {
        document.cookie = name + "=;expires=-1;path=" + path;
    }


    (function ($) {

        $(function () {
            var
                oDetailListLi = $(".detail-list li"),
                oDetailList = $(".detail-list"),
                oDetailListLiA = $(".detail-list li a"),
                oDetailListLiI = $(".detail-list li i"),
                oGoodClassifyH = $(".goods-classify h3"),
                oGoodClassify = $(".goods-classify"),
                oDetail = $(".detail"),
                oDetailIfoDiv = $(".detail-ifo div");

            var
                oBannerBn = $(".bn"),
                oBannerImgLi = $(".img-list li"),
                oBannerDirA = $(".dir-list a"),
                oBannerLeftBtn = $("#left-btn"),
                oBannerRightBtn = $("#right-btn"),
                oBannerDirList = $(".dir-list"),
                oBannerDirBtn = $(".dir-btn"),
                bIndex = 0,
                iTimer = null;

            var
                oMainRollMax = $(".roll1 .roll-max"),
                oMainRollTopA = $(".roll1 .roll-list a"),
                oMainRollMax2 = $(".roll2 .roll-max"),
                oMainRollTopA2 = $(".roll2 .roll-list a"),
                oMainRollMax3 = $(".roll3 .roll-max"),
                oMainRollTopA3 = $(".roll3 .roll-list a"),
                oMainRollMax3LeftBtn = $(".roll3-leftbtn"),
                oMainRollMax3RightBtn = $(".roll3-rightbtn"),
                rIndex = 0;

            var
                oFixBotMA = $(".fix1 .fix-bot-m-dirlist a"),
                oFixBotMA2 = $(".fix2 .fix-bot-m-dirlist a"),
                oFixBotMA3 = $(".fix3 .fix-bot-m-dirlist a"),
                oFixBotMA4 = $(".fix4 .fix-bot-m-dirlist a"),
                oFixBotMA5 = $(".fix5 .fix-bot-m-dirlist a"),
                oFixBotMA6 = $(".fix6 .fix-bot-m-dirlist a"),
                oFixBotMA7 = $(".fix7 .fix-bot-m-dirlist a"),
                oFixBotMLeftBtn = $(".fix-bot-m-left-btn"),
                oFixBotMRightBtn = $(".fix-bot-m-right-btn"),
                oFixBotImgList = $(".fix-bot-m-list"),
                fIndex = 1,
                flag = true,
                fTimer = null,
                oFixBotMid = $(".fix-bot-m"),
                oFixBotDirBtn = $(".fix-bot-m-dirbtn"),
                oFixBotDirList = $(".fix-bot-m-dirlist");

            var
                oHeaderSite = $(".header-site");


            $(window).scroll(function () {
                var scroll = document.body.scrollTop || document.documentElement.scrollTop;
                if (scroll >= 400) {
                    oHeaderSite[0].style.position = "fixed";
                    oHeaderSite[0].style.top = 0;

                } else {
                    oHeaderSite[0].style.position = "relative";
                }
            });


            var
                oSearch = $("#tx"),
                oSearchListLi = [],
                oSearchList = $("#search-list"),
                iIndex = -1;

            oSearch.focus(function () {
                oSearchList.css({display: "block"});
            });

            oSearch.blur(function () {
                oSearchList.css({display: "none"});
            });

            oSearch.bind("input", "propertychange", function () {
               /* $.getJSON(
                    "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?&json=1&p=3&sid=20939_1456_19036_17948_17001_20593_20856_20732_20836_20930&req=2&sc=eb&csor=1&cb=?",

                    /!*  "https://d.3.cn/index-1-todayRecommend-todayRecommend.js?callback=loadtodays&_=1474701797156",*!/

                    {wd: $(this).val()},
                    function (data) {
                        var sHtml = "";
                        data.s.forEach(function (v, k) {
                            sHtml += "<li><a href='javascript:;'>" + v + "</a></li>";
                        });
                        $("#search-list").html(sHtml);
                    }
                )*/



                $.ajax({
                    url:'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + oSearch.val() + '&json=1&p=3&sid=1421_20972_17948_21120_18560_20691_20885&req=2&csor=1&',
                    async:true,
                    dataType:'jsonp',
                    jsonp:'cb',
                    success:function(data){
                        console.log(data);
                        var sHtml = "";
                        data.s.forEach(function (v, k) {
                            console.log(v);
                            sHtml += "<li><a href='javascript:;'>" + v + "</a></li>";
                        });
                        $("#search-list").html(sHtml);
                        iIndex = -1
                    }
                });
            });

            oSearch.keydown(function (evt) {
                var event = evt || window.event;
                oSearchListLi = $("#search-list li");
                if (oSearchListLi.length && (event.keyCode === 38 || event.keyCode === 40)) {
                    if (event.keyCode === 38) {
                        iIndex--;
                        if (iIndex < 0) {
                            iIndex = oSearchListLi.length - 1;
                        }
                    }
                    if (event.keyCode === 40) {
                        iIndex++;
                        if (iIndex === oSearchListLi.length) {
                            iIndex = 0;
                        }
                    }
                    /*console.log(iIndex);*/
                    console.log(oSearchListLi);
                    $("#search-list li").removeClass("selected").eq(iIndex).addClass("selected");
                    oSearch[0].value = oSearchListLi[iIndex].innerText;
                    return false;

                }
            });


            oSearchList.mouseenter(function () {
                $("#search-list li").mouseover(function () {
                    iIndex = $(this).index();
                    $("#search-list li").removeClass("selected").eq(iIndex).addClass("selected");
                    oSearch[0].value = oSearchListLi[iIndex].innerText;
                    return false;
                });
            });


            oDetailListLi.mouseenter(function () {
                var iIndex = $(this).index();
                oDetailListLi.removeClass("over").eq(iIndex).addClass("over");
                oDetailListLiI.css({display: "none"}).eq(iIndex).css({display: "block"});
                oDetailIfoDiv.css({display: "none"}).eq(iIndex).css({display: "block"});
            });

            oGoodClassifyH.mouseenter(function () {
                oDetailList.css({display: "block"});
            });

            oGoodClassify.mouseleave(function () {
                oDetailList.css({display: "none"});
                oDetailIfoDiv.css({display: "none"});
                oDetailListLi.removeClass("over");
                oDetailListLiI.css({display: "none"});
            });

            oBannerDirA.mouseenter(function () {
                var iIndex = oBannerDirA.index($(this));
                bIndex = iIndex;
                oBannerDirA.removeClass("changeColor").eq(bIndex).addClass('changeColor');
                oBannerImgLi.fadeOut(500, "linear").eq(bIndex).stop(true).fadeIn(500, "linear");
            });

            oBannerLeftBtn.click(goLeft);

            oBannerRightBtn.click(goRight);

            iTimer = setInterval(goRight, 3000);

            oBannerBn.mouseenter(function () {
                clearInterval(iTimer);
                oBannerDirBtn.animate({opacity: 1}, 500, "linear");
                oBannerDirList.animate({opacity: 1}, 500, "linear");
            });

            oBannerBn.mouseleave(function () {
                iTimer = setInterval(goRight, 3000);
                oBannerDirBtn.animate({opacity: 0}, 500, "linear");
                oBannerDirList.animate({opacity: 0}, 500, "linear");
            });

            function goLeft() {
                bIndex--;
                if (bIndex < 0) {
                    bIndex = 9;
                }
                oBannerDirA.removeClass("changeColor").eq(bIndex).addClass('changeColor');
                oBannerImgLi.fadeOut(500, "linear").eq(bIndex).stop(true).fadeIn(500, "linear");
            }

            function goRight() {
                bIndex++;
                if (bIndex > 9) {
                    bIndex = 0;
                }
                oBannerDirA.removeClass("changeColor").eq(bIndex).addClass('changeColor');
                oBannerImgLi.fadeOut(500, "linear").eq(bIndex).stop(true).fadeIn(500, "linear");
            }

            oMainRollTopA.click(function () {
                var iIndex = oMainRollTopA.index($(this));
                console.log(iIndex);
                rIndex = iIndex;
                oMainRollMax.animate({left: -iIndex * 1200}, 500, "linear");
                oMainRollTopA.removeClass("roll-red").eq(iIndex).addClass("roll-red");

            });

            oMainRollTopA2.click(function () {
                var iIndex = oMainRollTopA2.index($(this));
                console.log(iIndex);
                rIndex = iIndex;
                oMainRollMax2.animate({left: -iIndex * 1200}, 500, "linear");
                oMainRollTopA2.removeClass("roll-red").eq(iIndex).addClass("roll-red");

            });

            oMainRollTopA3.click(function () {
                var iIndex = oMainRollTopA3.index($(this));
                rIndex = iIndex;
                console.log(rIndex);
                oMainRollMax3.animate({left: -iIndex * 1200}, 500, "linear");
                oMainRollTopA3.removeClass("roll-red").eq(iIndex).addClass("roll-red");

            });

            oMainRollMax3RightBtn.click(function () {
                if (rIndex < 3) {
                    rIndex++;
                }

                if (rIndex <= 3) {
                    oMainRollMax3.animate({left: -rIndex * 1200}, 500, "linear");
                    oMainRollTopA3.removeClass("roll-red").eq(rIndex).addClass("roll-red");
                }
            });

            oMainRollMax3LeftBtn.click(function () {
                if (rIndex > 0) {
                    rIndex--;
                }
                if (rIndex >= 0 && rIndex <= 3) {
                    oMainRollMax3.animate({left: -rIndex * 1200}, 500, "linear");
                    oMainRollTopA3.removeClass("roll-red").eq(rIndex).addClass("roll-red");
                }
            });


            oFixBotMA.mouseenter(function () {
                var iIndex = oFixBotMA.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA.removeClass("red").eq(fIndex - 1).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA2.mouseenter(function () {
                var iIndex = oFixBotMA2.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA2.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA3.mouseenter(function () {
                var iIndex = oFixBotMA3.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA3.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA4.mouseenter(function () {
                var iIndex = oFixBotMA4.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA4.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA5.mouseenter(function () {
                var iIndex = oFixBotMA5.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA5.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA6.mouseenter(function () {
                var iIndex = oFixBotMA6.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA6.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });

            oFixBotMA7.mouseenter(function () {
                var iIndex = oFixBotMA7.index($(this));
                fIndex = iIndex + 1;
                oFixBotMA7.removeClass("red").eq(iIndex).addClass("red");
                oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear");
            });


            oFixBotMid.mouseenter(function () {
                clearInterval(fTimer);
                oFixBotDirBtn.animate({opacity: 1}, 300, "linear");
                oFixBotDirList.animate({opacity: 1}, 300, "linear");
            });

            oFixBotMid.mouseleave(function () {
                oFixBotDirBtn.animate({opacity: 0}, 300, "linear");
                oFixBotDirList.animate({opacity: 0}, 300, "linear");
                fTimer = setInterval(fixGoRight, 3000);
            });

            oFixBotMLeftBtn.click(fixGoLeft);

            oFixBotMRightBtn.click(fixGoRight);

            fTimer = setInterval(fixGoRight, 3000);

            function fixGoLeft() {
                fIndex--;
                if (flag) {
                    flag = false;
                    oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear", function () {
                        flag = true;
                    });
                    if (fIndex == 0) {
                        fIndex = 4;
                        oFixBotImgList.animate({left: -4 * 356}, 1);
                    }
                    oFixBotMA.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA2.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA3.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA4.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA5.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA6.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA7.removeClass("red").eq(fIndex - 1).addClass("red");
                }
            };

            function fixGoRight() {
                fIndex++;
                if (flag) {
                    flag = false;
                    oFixBotImgList.animate({left: -(fIndex) * 356}, 200, "linear", function () {
                        flag = true;
                    });
                    if (fIndex == 5) {
                        fIndex = 1;
                        oFixBotImgList.animate({left: -1 * 356}, 1);
                    }
                    oFixBotMA.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA2.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA3.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA4.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA5.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA6.removeClass("red").eq(fIndex - 1).addClass("red");
                    oFixBotMA7.removeClass("red").eq(fIndex - 1).addClass("red");
                }
            };


            var
                sLoginAccount = $("#login-account"),
                sLoginPassword = $("#login-password"),
                sRegAccount = $("#reg-account"),
                sRegPassword = $("#reg-password"),
                sRegRandom = $("#reg-random"),
                oReadyReg = $("#ready-reg"),
                oGoShop = $("#go-shop");




            var
                oHint1 = $(".please1"),
                oHint2 = $(".please2");

            sRegAccount.blur(function () {
                oHint1.css({display: "none"});
            });

            sRegAccount.focus(function () {
                oHint1.css({display: "block"});
                oRegAccount.css({display: "none"});
            });

            sRegPassword.blur(function () {
                oHint2.css({display: "none"});
            });

            sRegPassword.focus(function () {
                oHint2.css({display: "block"});
                oRegPassWord.css({display: "none"});
            });


            var
                oRegAccount = $(".reg-okay1 p"),
                oRegPassWord = $(".reg-okay2 p"),
                oRegRandom = $(".random p"),
                oGetRandom = $(".get-random");


            var oSpan = $(".hit");

            var regId = /[0-9a-zA-Z]{6,20}/;

            var regEmail = /^\w+@\w+\.[a-zA-Z]{2,3}$/;

            var regPass = /[0-9a-zA-Z]{6,16}/;

            var regRandom = /[0-9]{4}/;

            var lose = $(".tx");

            lose.focus(function(){
                oRegRandom[0].style.display = "none";
            });

            var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
            var arr2 = [];
            var str = '';

            oGetRandom.click(function () {
                var a = parseInt(Math.random() * 10),
                    b = parseInt(Math.random() * 10),
                    c = parseInt(Math.random() * 10),
                    d = parseInt(Math.random() * 10);

                arr2 = [a, b, c, d];

                str = arr2.join("");

                console.log(str);

                oSpan[0].innerHTML = str;

                console.log(str);

                /*console.log(sRegRandom.val());*/

            });


            oReadyReg.click(function () {

                var
                    sRegAccountValue = sRegAccount.val(),
                    sRegPasswordValue = sRegPassword.val(),
                    sRegRandomValue = sRegRandom.val();


                var sId = regId.test(sRegAccountValue);
                var sEmail = regEmail.test(sRegAccountValue);
                var sPass = regPass.test(sRegPasswordValue);
                var sRandom = regRandom.test(sRegRandomValue);

                if ((sId == false && sEmail == false) && sPass == false) {
                    oRegAccount[0].style.display = "block";
                    oRegPassWord[0].style.display = "block";
                } else if (sId == false && sEmail == false) {
                    oRegAccount[0].style.display = "block";
                } else if (sPass == false) {
                    oRegPassWord[0].style.display = "block";
                } else if (sRegRandom.val() !== str) {
                    oRegRandom[0].style.display = "block";
                } else {
                    var
                        R_name = sRegAccount.val(),
                        R_pwd = sRegPassword.val();

                    var sName = getCookie("ZC");
                    flag = true;
                    if (sName === undefined) {
                        var aName = [];
                    } else {
                        var aName = JSON.parse(sName);
                    }

                    for (var i = 0; i < aName.length; i++) {
                        if (aName[i].name == R_name) {
                            flag = false;
                            alert("您已经注册过了");
                        }
                    }

                    if (flag) {
                        var oTemp = {
                            name: R_name,
                            pass: R_pwd
                        };
                        aName.push(oTemp);
                        setCookie("ZC", JSON.stringify(aName), 7, "/");
                        $("#reg-account")[0].value = "";
                        $("#reg-password")[0].value = "";
                        $("#reg-random")[0].value = "";
                        $(".hit").css({display: "none"});
                        oRegAccount[0].style.display = "none";
                        oRegPassWord[0].style.display = "none";
                        oRegRandom[0].style.display = "none";
                        alert("恭喜注册成功");
                        window.location.assign("http://localhost:63342/WWW/tps138/个人项目/html/register.html")
                    }
                    console.log(aName);
                }
            });


            var
                oLogCountPass = $(".log-okay p");


            var allName1 = getCookie("ZC");

            if (allName1 === undefined) {

            } else {
                var allName = JSON.parse(getCookie("ZC"));
            }


            var sChangeName = $(".change-name");


            oGoShop.click(function () {

                var
                    sLoginAccountValue = sLoginAccount.val(),
                    sLoginPasswordValue = sLoginPassword.val();
                $.each(allName, function (i, n) {
                    if (sLoginAccountValue === n.name && sLoginPasswordValue === n.pass){
                        setCookie("index", i, 7, "/");
                        alert("登陆成功");
                        window.location.assign("http://localhost:63342/WWW/tps138/个人项目/html/index.html");

                    }else/* if(sLoginAccountValue !== n.name || sLoginPasswordValue !== n.pass)*/{
                        oLogCountPass[0].style.display = "block";
                    }
                });
            });


            sLoginAccount.focus(function(){
                oLogCountPass[0].style.display = "none";
            });

            sLoginPassword.focus(function(){
                console.log(12);
                oLogCountPass[0].style.display = "none";
            });



            var indexName = getCookie("index");
            if (indexName === undefined) {
                sChangeName.text("登录");
            } else {
                sChangeName.text("欢迎" + allName[indexName].name + "登录");
            }


            var oGoodsBtn = $(".goods-btn a"),
                oGoodsUl = $(".goods-bot ul");

            oGoodsBtn.click(function () {
                var iIndex = $(this).index();
                oGoodsBtn.removeClass("red").eq(iIndex).addClass("red");
                oGoodsUl.removeClass("look").eq(iIndex).addClass("look");
            });


            var
                oBoxBotImg = $(".box-bot img"),
                oBoxTopImg = $(".bt-img img"),
                oScaleImg = $(".box-scale img");

            var
                oOrigin = $(".bt-img"),
                oMove = $(".scale-small"),
                oBig = $(".box-scale");

            var oBoxTop = $(".box-top");

            oBoxBotImg.mouseenter(function () {
                var iIndex = $(this).index();
                oBoxBotImg.removeClass("hover").eq(iIndex).addClass("hover");
                oBoxTopImg.removeClass("img-show").eq(iIndex).addClass("img-show");
                oScaleImg.removeClass("img-show").eq(iIndex).addClass("img-show");
            });

            oBoxTop.mouseenter(function () {
                oMove.css({display: "block"});
                oBig.css({display: "block"});
            });

            oBoxTop.mouseleave(function () {
                oMove.css({display: "none"});
                oBig.css({display: "none"});
            });


            var
                maxWidth = oOrigin.width() - oMove.width(),
                maxHeight = oOrigin.height() - oMove.height();

            var iScale = (oBig.width()) / (oMove.width());


            oBoxTop.mousemove(function (evt) {
                var event = evt || window.event;
                var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
                var x = event.clientX - oOrigin.offset().left - oMove.width() / 2;
                var y = event.clientY - oOrigin.offset().top - oMove.height() / 2 + scrollTop;
                /* console.log(event);*/

                if (x < 0) {
                    x = 0;
                }
                if (x > maxWidth) {
                    x = maxWidth;
                }

                if (y < 0) {
                    y = 0;
                }

                if (y > maxHeight) {
                    y = maxHeight;
                }

                oMove.css({left: x + "px", top: y + "px"});

                oScaleImg.css({left: -iScale * x + "px", top: -iScale * y + "px"});


            });


            var oGoShop2 = $(".o-2");
            var oCheck = $(".o-check");
            var oGoOnBuy = $(".mx-2");


            oGoShop2.click(function () {
                oCheck.css({display: "block"});
            });

            oGoOnBuy.click(function () {
                oCheck.css({display: "none"});
            });

            var oCheckLi = $(".c1-checkout li");
            var oSwitchDiv = $(".c2-m div");

            oCheckLi.click(function () {
                var iIndex = $(this).index();
                oCheckLi.removeClass("on").eq(iIndex).addClass("on");
                oSwitchDiv.removeClass("c2-m-show").eq(iIndex).addClass("c2-m-show");
                /* oSwitchDiv.fadeOut(300).eq(iIndex).fadeIn(300);*/
            });


            var oGoTop = $(".go-top");

            $(window).scroll(function () {
                var scroll = document.body.scrollTop || document.documentElement.scrollTop;

                if (scroll >= 1500) {
                    oGoTop.css({display: "block"});
                } else {
                    oGoTop.css({display: "none"});
                }

                oGoTop.click(function () {

                    document.body.scrollTop = 0;

                    document.documentElement.scrollTop = 0;

                });
            });


            //购物车信息！important------------------------------------------------------------------

            var g_Name = $(".gName").text();
            var g_Price = $(".gPrice").text();
            var iTotal = $(".total-num").text();

            var
                iNumMiu = $('.bot-btn'),
                iNumAdd = $('.top-btn');
            var count = 1;
            iNumMiu.click(function () {
                if (count == 0) {

                } else {
                    count--;
                    $(".gNum").val(count);
                }
            });

            iNumAdd.click(function () {
                if (count >= iTotal) {
                } else {
                    count++;
                    $(".gNum").val(count);
                }
            });


          /*  var oJie = $(".mx-1");*/

           /* var oJie2 = $('.o-2');*/

            oGoShop2.click(function () {

                    var g_Num = $(".gNum").val();

                    console.log(g_Num);

                    if(g_Num<=0){

                    }else{
                        var

                            sGoods = getCookie("goods"),
                            bBtn = true;

                        if (sGoods === undefined) {
                            var aGoods = [];
                        } else {
                            var aGoods = JSON.parse(sGoods);
                        }

                        for (var i = 0; i < aGoods.length; i++) {
                            if (aGoods[i].name == g_Name) {
                                var sz = parseInt(aGoods[i].num);
                                sz += parseInt($(".gNum").val());
                                aGoods[i].num = sz;
                                bBtn = false;
                            }
                        }

                        if (bBtn) {
                            var oGoods = {
                                name: g_Name,
                                price: g_Price,
                                num: g_Num
                            };
                            aGoods.push(oGoods);
                        }

                        setCookie("goods", JSON.stringify(aGoods), 7, "/");
                    }



            });



            var sH1 = $(".dd-fl");

            var sHtml = "";

            var sH2 = $(".two");

            var sHtml2 = "";

            var mxGoods1 = getCookie("goods");

            if (mxGoods1 === undefined) {

            } else {
                var mxGoods = JSON.parse(getCookie("goods"));

                /*for (var i = 0; i < mxGoods.length; i++) {
                    sHtml += '<div class="hero"><div class="col-md-5 mx-clear"><div class="g-pic"><img src="../img/0.jpg" title="" class="img100"></div><div class="g-info"><p><a href="javascript:;" class="goods-name"></a></p></div></div><span class="col-md-2 center"></span> <span class="col-md-1 center">￥<i class="single-price"></i></span> <span class="col-md-2 center"><a href="javascript:;" class="minus num-btn sec-min">-</a><input type="text" class="now-num" value="1"><a href="javascript:;" class="add num-btn sec-add">+</a></span><span class="col-md-1 center">￥<i class="buy-red"></i></span><span class="col-md-1 center delete">删除</span></div>';
                    sH1.html(sHtml);
                };*/


                /*for(var j = 0;j< mxGoods.length; j++){
                 sHtml2 += '<div class="look"><span class="xx1"><img src="../img/0.jpg" alt=""><p class="xx1-name"></p></span><span class="xx2">￥<b class="xx1-price"></b></span><span class="xx3"></span></div>';
                 sH2.html(sHtml2);
                 };*/


                //  首先将框架拿到，然后在后续拿到相应的数据

                $.each(mxGoods,function(i,v){
                sHtml += '<div class="hero"><div class="col-md-5 mx-clear"><div class="g-pic"><img src="../img/0.jpg" title="" class="img100"></div><div class="g-info"><p><a href="javascript:;" class="goods-name"></a></p></div></div><span class="col-md-2 center"></span> <span class="col-md-1 center">￥<i class="single-price"></i></span> <span class="col-md-2 center"><a href="javascript:;" class="minus num-btn sec-min">-</a><input type="text" class="now-num" value="1"><a href="javascript:;" class="add num-btn sec-add">+</a></span><span class="col-md-1 center">￥<i class="buy-red"></i></span><span class="col-md-1 center delete">删除</span></div>';
                sH1.html(sHtml);
            });

            $.each(mxGoods,function(i,v){
                sHtml2 += '<div class="look"><span class="xx1"><img src="../img/0.jpg" alt=""><p class="xx1-name"></p></span><span class="xx2">￥<b class="xx1-price"></b></span><span class="xx3"></span></div>';
                sH2.html(sHtml2);
            })
        };


            var iTotalMoney = $(".all_money");

            var iSelfMoney = $(".buy-red");

            var iSingleMoney = $(".single-price");

            var iNowNum = $(".now-num");

            var sBuyName = $(".goods-name");

            var oDelete = $(".delete");

            var oLastMin = $(".sec-min");

            var oLastAdd = $(".sec-add");

            var iAllTotal = 0;

            var all_Money  =$(".zongji");


            $.each(mxGoods, function (i, n) {

                sBuyName.eq(i).text(n.name);

                iSingleMoney.eq(i).text(n.price);

                iSelfMoney.eq(i).text(n.num* n.price);

                iNowNum.eq(i).val(n.num);

                iAllTotal += n.num * n.price;
            });


            var xxx_name = $(".xx1-name");
            var xxx_price = $(".xx1-price");
            var xxx_num   = $(".xx3");


            $.each(mxGoods,function(i,n){

                xxx_name.eq(i).text(n.name);

                xxx_price.eq(i).text(n.price);

                xxx_num.eq(i).text(n.num);

                console.log(mxGoods);

            });

            all_Money.text(iAllTotal);

            oLastAdd.click(function(){

                iAllTotal = 0;

                var iIndex = oLastAdd.index($(this));

                var s = iNowNum.eq(iIndex).val();

                s++;

                iNowNum.eq(iIndex).val(s);

                var mm = iSingleMoney.eq(iIndex).text();

                iSelfMoney.eq(iIndex).text(s*mm);

                mxGoods[iIndex].num = s;

                setCookie("goods",JSON.stringify(mxGoods),7,"/");

                var sss = JSON.parse(getCookie("goods"));
                console.log(sss);

                $.each(sss,function(i,n){
                    iAllTotal += n.num * n.price;
                });

                iTotalMoney.text(iAllTotal);

            });


            oLastMin.click(function(){

                iAllTotal = 0;

                var iIndex = oLastMin.index($(this));

                var s = iNowNum.eq(iIndex).val();

                s--;

                if(s>=0) {
                    iNowNum.eq(iIndex).val(s);

                    var mm = iSingleMoney.eq(iIndex).text();

                    iSelfMoney.eq(iIndex).text(s * mm);

                    mxGoods[iIndex].num = s;

                    setCookie("goods", JSON.stringify(mxGoods), 7, "/");

                    var mmm = JSON.parse(getCookie("goods"));

                    $.each(mmm, function (i, n) {
                        iAllTotal += n.num * n.price;
                    });

                    iTotalMoney.text(iAllTotal);
                }else{

                }


            });




            iTotalMoney.text(iAllTotal);

            var oHero = $(".hero");

                oDelete.click(function (){

                    iAllTotal = 0;

                    var iIndex = oDelete.index($(this));

                    oHero.eq(iIndex).remove();

                    mxGoods.splice(iIndex,1);

                    setCookie("goods", JSON.stringify(mxGoods), 7, "/");

                    var ccc = JSON.parse(getCookie("goods"));

                    console.log(ccc);

                    $.each(ccc,function(i,n){
                        iAllTotal += n.num * n.price;
                    });

                    iTotalMoney.text(iAllTotal);

                    window.location.assign("http://localhost:63342/WWW/tps138/个人项目/html/goods-account.html")

                });




            if (getCookie("goods") === undefined) {

            } else {
                $(".car-num").html(JSON.parse(getCookie("goods")).length);
            }

        });








    })(jQuery);

};

function setCookie(name,value,expires,path){
    var oDate=new Date();
    oDate.setDate(oDate.getDate()+expires);
    document.cookie=name+"="+decodeURIComponent(value)+";expires="+oDate+";path="+path;
}

function getCookie(name){
    var aCookie=document.cookie.split("; ");
    for(var i=0;i<aCookie.length;i++){
        var aTemp=aCookie[i].split("=");
        if(aTemp[0]===name){
            return decodeURIComponent(aTemp[1]);
        }
    }
}


function removeCookie(name, path) {
    document.cookie = name + '=;expires=-1;path=' + path;
}